package io.renren.modules.zhongyi.controller;


import io.renren.common.utils.R;
import io.renren.modules.zhongyi.entity.CollectionBean;
import io.renren.modules.zhongyi.entity.ZYWeChatUserEntity;
import io.renren.modules.zhongyi.service.ZYUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/zy_user")
@Api(tags = "用户相关")
public class UserController {

    @Autowired
    ZYUserService service;

    @PostMapping("userInfo")
    @ApiOperation("获取用户信息")
    public R getUserInfoData(@RequestBody Map map){

        String openId = (String) map.get("openId");

        System.out.println("openId-----------" + openId);

        if (openId == null || openId.length()<=0){

            return R.ok("请上传openId");
        }
        ZYWeChatUserEntity userEntity = service.getUserInfoData(openId);



        return R.ok().put("data",userEntity);
    }

    @PostMapping("getUserCollectionCourse")
    @ApiOperation("获取用户收藏课程")
    public R getUserCollectionCourse(@RequestBody Map map){
        String openId = (String) map.get("openId");

        List<CollectionBean> bean = service.getUserCollectionCourse(openId);
        if (bean == null){
            return R.ok("暂无数据");
        }
        return R.ok().put("data",bean);
    }


}
